import request from '@/api/axios'
import {AxiosPromise} from 'axios'
import {DataRes, DataRecordList} from '@/api/config'

import {Paging} from '@/api/config'
import {MenuView} from '@/store/nav'
export interface GetRoleList extends Paging {
  roleName?: string | null
}

export type TableOperation = 'add' | 'deletes'

//角色基础信息
export interface BaseRoleInfor {
  roleName: string //角色名称
  remark?: string
  createUser?: string //创建者
  createTime?: string //创建时间
  menuJson?: string | null
}

//角色信息
export interface RoleInfor extends BaseRoleInfor {
  id: string
}

export interface System {
  systemName: string
}

export type RoleFormInfor = Partial<RoleInfor & System>

//获取角色列表
export const getRoleList = (
  params: any
): AxiosPromise<any> => {
  return request({
    url: '/api/book/list',
    method: 'get',
    params
  })
}

//角色关联菜单信息
export interface RoleMenuData {
  roleId?: string
  menuId: string
}

//角色已关联菜单信息
export interface RoleHasMenuData extends RoleMenuData {
  id?: string
}

//角色关联按钮信息
export interface RoleButtonData {
  roleId?: string
  menuId: string
  menuButtonId: string
}

//角色已关联按钮信息
export interface RoleHasButtonData extends RoleButtonData {
  id?: string
}

//角色关联功能信息
export interface RoleFunData {
  roleId?: string
  functionId: string
}

//角色已关联按钮信息
export interface RoleHasFunData extends RoleFunData {
  id?: string
}

//角色详细信息
export interface RoleDetailInfor {
  menuCheckedList: Array<string> // 菜单勾选code
}

export type RoleSaveInfor = RoleFormInfor
//保存角色信息
export const saveRoleInfor = (
  data: RoleSaveInfor
): AxiosPromise<DataRes<undefined>> => {
  return request({
    url: '/api/role/save',
    method: 'post',
    data
  })
}

//删除角色
export const deleteRoles = (
  data: Array<string>
): AxiosPromise<DataRes<undefined>> => {
  return request({
    url: '/api/role/remove',
    method: 'post',
    data
  })
}

//搜索
export interface SearchRoleFromData {
  roleName: null | string
}